<?php if (!defined('BASEPATH')) exit('No direct script access allowed');?>

<div class="col-lg-12">
    <?php
    echo form_open(base_url($this->config->item('area_admin') . '/locacoes/salvar'), 'id="editar_locacao"'); 
        
    $locacao_id = (isset($locacao->id))? $locacao->id: set_value('id');
    $locacao_id = ($locacao_id === '' && isset($id))? $id: $locacao_id;
    
    
    
    $atributos = array(
        'name'  => 'id',
        'id'    => 'locacao_id',
        'value' => (isset($locacao->id))? $locacao->id: $locacao_id,
        'type'  => 'hidden'
    );
    
    echo form_input($atributos);
    
    echo form_input(array(
        'name' => 'base_url',
        'id' => 'base_url',
        'type' => 'hidden',
        'value' => base_url($this->config->item('area_admin'))
    ));
    
    echo form_input(array(
        'name' => 'cliente_id',
        'id' => 'cliente_id',
        'type' => 'hidden',
        'value' => (isset($locacao->cliente_id))? $locacao->cliente_id : set_value('cliente_id')
    ));
    ?>
    
    
    
    
    <div class="row">
       <div class="form-group col-lg-2">
            <?php 

            echo form_label('Cliente');
            
            echo form_input('cliente',(isset($locacao->nome_cliente)? $locacao->nome_cliente: set_value('cliente')), 'id = "cliente" class="form-control "');

            ?>
        </div>
    </div>
    
    <div class="row">
       <div class="form-group col-lg-2">
            <?php 

            
            echo form_label('Filme');
            
            echo form_input('filme','', 'class="form-control " id="filme"');
          
            
            ?>
        </div>
            </div>
    
    <div class="row">
        
        <div class="form-group col-lg-6">
            <table id ="tabela_filmes" border="1" class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th><label> Filme </label></th>
                        <th><label> Valor </label></th>
                        <th><label> Ações </label></th>
                    </tr>
                </thead>
                
                <tbody id="div_filmes">
                     
                    <?php
                        if(isset($locacao->filmes) && isset($locacao->id)){
                            $filmes = $locacao->filmes;
                            foreach($filmes as $f){
    //                            echo 'Entrou';
                                //echo '<tr><td><input type= "hidden" name="filmes[]" value="'+ $f->id+'" >';
                                //echo '<label>'+$f->nome+'</label></td><td width="50"><input type="button" name="botao-ok" value="Remover" class="btn btn-danger btn_cancelar"></td></td></tr>';
                                echo '<tr id="f'.$f->id.'">';
                                
                                echo '<td>';
                                echo '<input type="hidden" name="filmes[]" class = "filme" value="'.$f->id.'" />';
                                echo '<label>'.$f->nome.'</label>';
                                echo '</td>';
                                echo '<td>';                                
                                echo '<label>'.$f->valor.'</label>';
                                echo '</td>';
                                echo '<td width="50">';
                                echo '<input type="button" name="botao-ok" data-filme="f'.$f->id.'" data-valor="'.$f->valor.'" value="Remover" class="btn btn-danger btn_remove_filme" >';
                                echo '</td>';
                                echo '</tr>';
                                
                            }
                        }
                        
                    ?>
                </tbody>
                
            </table>
          
        </div>
        
    </div>
    
    <div class="row">
        <div class="form-group col-lg-2">
            <?php
            if(isset($locacao->data)){
                list($ano, $mes, $dia) = explode("-", $locacao->data);
                list($dia2, $hora) = explode(" ", $dia);

                $locacao->data = $dia2.'/'.$mes.'/'.$ano;
            }
            echo form_label('Data');
            $data_posterior = date('d/m/Y', strtotime("+1 days"));
            echo form_input('data', (isset($locacao->data)? $locacao->data : $data_posterior), 'id="data" class="form-control" ');
            echo form_error('data');
            ?>
        </div> 
        
    </div>

    <div class="row">
        <div class="form-group col-lg-2">
            <?php 

            echo form_label('Valor');
            echo form_input('valor',(isset($locacao->valor)? $locacao->valor:0), 'id= "valor" class="form-control"');
            echo form_error('valor');
            ?>
        </div>
    </div>
    
    <div class="row">
        <div class="form-group col-lg-2">
            <?php 

            echo form_label('Status');

            $status_locacao = $this->config->item('status_locacao');

            echo form_dropdown('status',$status_locacao,(isset($locacao->status)? $locacao->status: set_value('status')),'class="form-control"');
            echo form_error('status');
            ?>
        </div>
    </div>
    
   
    
    <div class="row" style="padding-top: 20px;">
        <div class="form-group col-lg-6">
            <?php 

            echo form_submit('salvar','Salvar', 'class="btn btn-primary"');

            echo '&nbsp;' . form_button('cancelar','Cancelar', ' class="btn btn-danger btn_cancelar" ');
            ?>
        </div>
    </div>
    
    <?php echo form_close(); ?>
</div> 